/**
 * ...
 * @author Thot
 */

function TextureProxy()
{
	this.init( TextureProxy.NAME, new Array() );
}

POO.extend( TextureProxy, Proxy );


	// static
	
	TextureProxy.NAME = "TextureProxy";

	
	//private
	TextureProxy.prototype._loader 	= null;
	TextureProxy.prototype._list 	= null;
	
	//public
	
	TextureProxy.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [ p_name, p_data ] );
		this._loader = new ImageLoader();
		this._loader.signal.addListener( ImageLoader.LOAD_PROGRESS, this._loadProgressHandler, this );
		this._loader.signal.addListener( ImageLoader.LOAD_COMPLETE, this._loadCompleteHandler, this );
		this.listenNotifications();
	};
	
	TextureProxy.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.LOAD_PROJECT_COMPLETE, this.onNotification );
	};

	TextureProxy.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.LOAD_PROJECT_COMPLETE:	
				this._loadTextures(); 
				break;
		}
	};
	
	
	// private
	TextureProxy.prototype._loadTextures = function( p_from, p_to )
	{
		this._list = new Array();
		this._loader.clean();
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var data = proxy.getTexturesList();
		var i = 0;
		var max = data.length;
		
		for( ; i < max; i++ )
		{
			this._loader.addFile(data[i], i);
			this._list.push( data[i] );
		}
		
		this._loader.load();
	};
	
	TextureProxy.prototype._loadProgressHandler = function()
	{
		var progression = this._loader.getProgression();
		this.getFacade().sendNotification(ApplicationNotification.LOAD_DATA_PROGRESS, {"progression":progression});
	};
	
	TextureProxy.prototype._loadCompleteHandler = function()
	{
		var appProxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var manager = TextureManager.getInstance();
		var data = this._loader.getData();
		var texture = null;
		var id = null;
		
		for( id in data )
		{
			texture = SmartTexture.createTexture();
			texture.id = parseInt(id);
			texture.data = data[id];
			texture.type = Texture2D.BMP_TEXTURE;
			manager.addTexture( texture );
		}
		
		this.getFacade().sendNotification(ApplicationNotification.LOAD_DATA_COMPLETE);
	};
	
	TextureProxy.prototype.getTexturesList = function()
	{
		return this._list;
	};

	
	